<template>
  <div>
    <el-row>
    <el-tooltip effect="dark" placement="right" v-for="(item,index) in books.slice((currentPage-1)*pageSize,currentPage*pageSize)" :key="index">
      <template v-if="index < 8">
        <p slot="content" style="font-size: 14px;margin-bottom: 6px;">{{ item.title }}</p>
        <p slot="content" style="font-size: 13px;margin-bottom: 6px">
          <span>{{ item.author }}</span> /
          <span>{{ item.date }}</span> /
          <span>{{ item.press }}</span>
        </p>
        <p slot="content" class="abstract">{{ item.abs }}</p>
        <el-card style="height:300px;width: 220px;float: left;margin: 10px 15px 20px 30px;"
                 class="book"
                 bodyStyle="padding:10px"
                 shadow="hover"
                 @click.native="showBook(item.id)">
          <div class="cover" style="width: 200px;height: 222px ;overflow: hidden;cursor: pointer;">
            <img :src="item.cover" alt="封面" style="width: 200px;height: 232px">
          </div>
          <div class="info">
            <div class="title">
              <a href="">{{ item.title }}</a>
            </div>
          </div>
          <div class="author">{{ item.author }}</div>
        </el-card>
      </template>
    </el-tooltip>
    </el-row>
    <el-row>
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          :total="books.length">
      </el-pagination>
    </el-row>
  </div>
</template>
<script>
export default {
  name: "collect",
  data(){
    return{
      imgList:[
        {
          id:'1',
          url:'https://bossaudioandcomic-1252317822.image.myqcloud.com/activity/document/414bfff93f01782f0dbb25fa1aefa567.jpg'
        },{
          id:'2',
          url:'https://bossaudioandcomic-1252317822.image.myqcloud.com/activity/document/88cc5e36efaa52ee18dfb400ca3393f9.jpg'
        },{
          id:'3',
          url:'https://bossaudioandcomic-1252317822.image.myqcloud.com/activity/document/7bbf0a623a0c2ece64efaa5aec18cf5f.jpg'
        },
      ],
      books: [],
      currentPage: 1,
      pageSize: 10
    }
  },
  mounted: function () {
    this.loadBooks()
  },
  methods: {
    loadBooks() {
      this.$axios.get('/getBookCollects?userId='+localStorage.getItem('userId'),).then(resp => {
        if (resp && resp.status === 200) {
          this.books = resp.data
          this.currentPage = resp.data.length/this.pageSize
        }
      })
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage
    },
    searchResult() {
      this.$axios.get('/search?keywords=' + this.$refs.searchBar.keywords, {}).then(resp => {
        if (resp && resp.status === 200) {
          this.books = resp.data
        }
      })
    },
    showBook(id) {
      window.localStorage.setItem('bookId', id)
      this.$router.push({path: `/book/${id}`});
    }
  }
}
</script>
<style>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
.cover {
  width: 200px;
  height: 222px ;
  overflow: hidden;
  cursor: pointer;
}

img {
  width: 115px;
  height: 172px;
}

.title {
  font-size: 14px;
  text-align: left;
}

.author {
  color: #333;
  width: 102px;
  font-size: 13px;
  margin-bottom: 6px;
  text-align: left;
}

.abstract {
  display:-webkit-box;
  line-height: 17px;
  width: 300px;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:3;
  overflow:hidden;
}

a {
  text-decoration: none;
}

a:link, a:visited, a:focus {
  color: #3377aa;
}

.el-icon-circle-plus-outline {
  margin: 50px 0 0 20px;
  font-size: 100px;
  float: left;
  cursor: pointer;
}
</style>